package com.tj.collection.controller.lending;

import com.fqgj.common.utils.CollectionUtils;
import com.tj.collection.bean.ApiResponse;
import com.tj.collection.controller.lending.response.ClOrderHistoryResponse;
import com.tj.collection.db.dao.ClAllocationDetailDao;
import com.tj.collection.db.dao.ClReceiverDao;
import com.tj.collection.db.entity.ClReceiverEntity;
import com.tj.collection.db.entity.business.ClOrderAllocationEntity;
import org.hibernate.validator.constraints.NotBlank;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: pavan
 * Date: 2017/8/7
 * Time: 下午 19:50
 */
@RestController
@RequestMapping("/usercollection")
public class UserCollectionController {

    @Autowired
    private ClReceiverDao clReceiverDao;

    @Autowired
    private ClAllocationDetailDao allocationDetailDao;

    /**
     * 查询用户的催收历史
     *
     * @param
     * @return 催收历史
     */
    @RequestMapping("/overdue/history/{userCode}/query")
    public ApiResponse<ClOrderHistoryResponse> getOverdueHistoryByUserCode(@PathVariable @NotBlank(message = "userCode不能为空") String userCode) {
        List<ClReceiverEntity> clReceiverEntityList = clReceiverDao.selectListByUserCode(userCode);
        if (CollectionUtils.isEmpty(clReceiverEntityList)) {
            return new ApiResponse<>();
        }
        List<ClOrderAllocationEntity> clOrderAllocationEntityList = allocationDetailDao.selectCollectionAllocationHistoryList(userCode);
        return new ApiResponse<>(new ClOrderHistoryResponse(clOrderAllocationEntityList));
    }
}
